package nqueens.chessStuff;

public class Queen implements Comparable<Queen> {
    private Square sq = null;
    public final int IDENTIFIER; // a unique identifier for this specific queen

    /**
     * Constructor for the queen with a unique identifier represented by an int for
     * placement into a set of queens
     * @param identifier a unique identifier for the queen
     */
    public Queen (int identifier) {
        this.IDENTIFIER = identifier;
        sq = null;
    }

    /**
     * Package level access only so the algorithm can't access it
     * @param sq the square the queen has been placed on
     */
    void placeQueen(Square sq) {
        this.sq = sq;
    }

    /**
     * Package level access only so the algorithms can't access it
     * @return the square the queen was removed from
     */
    Square removeQueen() {
        Square s = sq;
        sq = null;
        return s;
    }

    /**
     * Getter for the square this queen is on.  The return value can be null.
     * @return The square this queen is placed on.
     */
    public Square getSquare() {
        return sq;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Queen other = (Queen) obj;
        if (this.IDENTIFIER != other.IDENTIFIER) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + this.IDENTIFIER;
        return hash;
    }

    public int compareTo(Queen that) {
        return this.IDENTIFIER - that.IDENTIFIER;
    }
}
